package com.xiaoxin.errorDemo.error;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@ControllerAdvice
public class CustomControllerAdvice extends ResponseEntityExceptionHandler {

    @ExceptionHandler(Exception.class)
    String handleException(Exception e, HttpServletRequest request) {
        Map<String, Object> outMap = new HashMap<>();
        outMap.put("meg", e.getMessage());
        request.setAttribute("ext", outMap);
        return "forward:/error";
    }

}